home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_08
/
weber
/
gui.h
< prev
next >
Wrap
Text File
|
1993-03-11
|
17KB
|
357 lines
/***************************************************************
* file: GUI.H
* purpose: simple gui prototypes, defines and data structures
* copyright: 1991 by David Weber. All rights reserved.
* This software can be used for any purpose as object, library or executable.
* It cannot be sold for profit as source code.
* history:
* 12-17-91 - initial code
* 01-31-93 - this code is now obsolete, see the CPP gui package
**************************************************************/
#ifndef _GUI
#define _GUI
#ifdef DEBUG
#define FG_SYNCHRONIZED /* allow zdb to check heap buffers */
#endif
#include <fg.h>
#include "keys.h"
/* --------- SYSTEM DEFAULTS --------- */
/* standard colors */
#define COLOR_SYSTEM_BACKGROUND FG_BLACK
#define COLOR_MESSAGE_BACKGROUND FG_RED
#define COLOR_MESSAGE_FOREGROUND FG_WHITE
#define COLOR_MENU_FOREGROUND FG_WHITE
#define COLOR_MENU_BACKGROUND FG_BLUE
#define COLOR_MENU_GRAY FG_GRAY
#define COLOR_MENU_HIGHLIGHT FG_LIGHT_CYAN
#define COLOR_MENU_FOCUS FG_LIGHT_GREEN
#define COLOR_DIALOG_FOREGROUND FG_LIGHT_WHITE
#define COLOR_DIALOG_BACKGROUND FG_CYAN
#define COLOR_DIALOG_HIGHLIGHT FG_LIGHT_CYAN
#define COLOR_DIALOG_SELECTION FG_LIGHT_GREEN
#define COLOR_DIALOG_GRAY FG_GRAY
#define COLOR_DIALOG_FOCUS FG_YELLOW
/* --------- GUI.C, MESSAGES AND OBJECTS --------- */
/* message box info */
#define MESSAGE_MAX_STR 80 /* maximum size of a message string */
#define MESSAGE_YN " Y/N?" /* Y/N appendage */
#define MESSAGE_YES 'y' /* Yes, lower case */
#define MESSAGE_NO 'n' /* No, lower case */
/* message id defines */
/* system messages */
#define M_MIN_SYSTEM 0 /* minimum system message */
#define M_NONE 0 /* null message */
#define M_START 1 /* startup message */
#define M_QUIT 2 /* quit message */
#define M_MAX_SYSTEM 99 /* maximum system message */
/* input messages */
#define M_MIN_INPUT 100 /* minimum input message */
#define M_KEY 100 /* keyboard hit, key value in short_data.x */
#define M_MOUSE_LEFT 101 /* mouse left button went down, x,y coordinates in short_data */
#define M_MOUSE_CENTER 102 /* mouse center button went down, x,y coordinates in short_data */
#define M_MOUSE_RIGHT 103 /* mouse right button went down, x,y coordinates in short_data */
#define M_MAX_INPUT 199 /* maximum input message */
/* error messages, address of function causing error is found in message->data.ptr_data */
#define M_MIN_ERROR 200 /* minimum error message */
#define M_NULL_ERROR 200 /* an undefined error occurred */
#define M_NOMEM 201 /* memory allocation failed */
#define M_MESSAGE_OVERFLOW 202 /* message queue overflowed and messages were lost */
#define M_INVALID_PARMS 203 /* invalid parameters passed to a function */
#define M_NOT_OPEN 204 /* attempt to access an unopened object */
#define M_MAX_ERROR 255 /* maximum error message */
/* all messages 256 and greater are user defined for dialog controls etc. */
/* message structure */
struct two_shorts { short x,y; };
union data_list
{
long long_data;
void *ptr_data;
struct two_shorts short_data;
};
typedef struct
{
short id; /* message id from list above or user defined */
union data_list data; /* message data can be a long, pointer or two shorts */
} MESSAGE;
/* graphical objects */
#define OBJECT_NULL 0 /* object types */
#define OBJECT_MENU 1
#define OBJECT_POPUP 2
#define OBJECT_MESSAGEBOX 3
#define OBJECT_DIALOG 4
typedef struct object_list
{
short id; /* object type from defines above */
void (*message_handler)(MESSAGE *,void *); /* object message handler */
void *data; /* pointer to object data */
fg_box_t screen; /* object screen extent */
fg_handle_t save_area; /* handle of area saved under object */
struct object_list *next; /* next object in list or NULL */
} GOB;
typedef void (*GENERIC_MESSAGE_HANDLER)(MESSAGE *message,void *);
/* global data */
extern short gui_errno; /* last error message */
#ifndef GUI_SOURCE
extern const short gui_screen_width,gui_screen_height; /* gui screen dimensions */
extern const short gui_char_width,gui_char_height; /* gui text cell dimensions */
#endif
/* prototypes */
short gui_open(void); /* must be called before using gui */
void gui_close(void); /* called after finished with gui */
short object_add(short id,void (*message_handler)(MESSAGE *message,void *data),void *data,fg_pbox_t screen); /* add object to active list */
short object_remove(void *data); /* removes object from active list */
GOB *object_exists(void *data); /* returns pointer to object or NULL if none */
short message_get(MESSAGE *message); /* gets next message from input devices or system */
void message_send(MESSAGE *message); /* send a message down the list */
short message_send_object(MESSAGE *message,void *data); /* send a message to a particular object */
short message_box(char *str); /* puts a message box on the screen */
short error_box(short id); /* displays a box for errors */
short yn_box(char *str); /* displays a message box and waits for y/n response */
short exclusive_focus_set(void *data); /* sets focus to a particular object */
short exclusive_focus_clear(void *data);/* clears focus restriction */
void input_handler_set_default(void (*message_handler)(MESSAGE *message)); /* message handler to be invoked when no other objects want message */
void screen_clear(void); /* clears screen to system background color */
/* --------- MENU.C, MENUS AND POPUPS --------- */
/* sizes */
#define MENU_MAX_ITEMS 64
#define POPUP_MAX_ITEMS 64
/* popup submenus */
typedef struct popup_item
{
short id; /* associated message id */
char *name; /* name of item, note: use of '&' will highlight next character */
short accelerator; /* accelerator key or 0 if none */
unsigned short status; /* see status defines below */
/* end of initialized data */
fg_box_t screen; /* hotspot on screen, filled in when menu is opened */
struct popup_item *next;/* pointer to next item in list or NULL if end, filled in when menu is opened */
} POPUP_ITEM;
/* menu status */
#define MENU_ACTIVE 1
#define MENU_GRAY 2
#define MENU_HIDDEN 4
#define MENU_STATUS_MASK (MENU_ACTIVE | MENU_GRAY | MENU_HIDDEN)
#define MENU_SELECTED 8
#define MENU_BITS 0x000f
/* menu bars are linked lists of this struct */
typedef struct menu_item
{
short id; /* associated message id */
char *name; /* name of item, note: use of '&' will highlight next character */
short accelerator; /* accelerator key or 0 if none */
POPUP_ITEM *popup; /* pop up associated with menu item, or NULL if none */
short number_of_popup_items; /* number of items in associated popup or 0 if none */
unsigned short status; /* see status defines above */
/* end of initialized data */
fg_box_t screen; /* hotspot on screen, filled in when menu is opened */
struct menu_item *next; /* pointer to next item in list or NULL if end, filled in when menu is opened */
} MENU_ITEM;
/* menu prototypes */
short menu_open(MENU_ITEM menubar[],short number_of_items); /* draws a menubar */
void menu_message_handler(MESSAGE *message,MENU_ITEM *menu); /* handles messages for menus */
short menu_close(MENU_ITEM menubar[]); /* erases a menubar */
short menu_modify(MENU_ITEM menubar[],short menu_id,unsigned short status); /* modifies the status of a menu item, ACTIVE, GRAY or HIDDEN */
short menu_clear(MENU_ITEM menubar[]); /* clear any open popups */
short popup_open(POPUP_ITEM popup[],short number_of_items,short x,short y);